function html2bb(s) {
s = s.replace(/ <br \/> /g, "\n");
s = s.replace(/<br \/>/g, "\n");
s = s.replace(/<p>/g, "\n\n");
s = s.replace(/ <p> /g, "\n\n");
s = s.replace(/\n /g, "\n");
s = s.replace(/ \n/g, "\n");
s = s.replace(/  /g, " ");
// [b][/b]
s = s.replace(/<b>/g, "[b]");
s = s.replace(/<\/b>/g, "[/b]");
// [u][/u]
s = s.replace(/<u>/g, "[u]");
s = s.replace(/<\/u>/g, "[/u]");
// [i][/i]
s = s.replace(/<i>/g, "[i]");
s = s.replace(/<\/i>/g, "[/i]");
return s;
}

function html2bbBrief() {
if (document.getElementById("brief").value!="") {
document.getElementById("format_brief").checked = true;
var s = document.getElementById("brief").value;
document.getElementById("brief").value = html2bb(s);
}
}

function html2bbMessage() {
if (document.getElementById("message").value!="") {
document.getElementById("format_message").checked = true;
var s = document.getElementById("message").value;
document.getElementById("message").value = html2bb(s);
}
}

function html2bbBriefAndMessage() {
html2bbBrief();
html2bbMessage();
}